import org.junit.Test;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.Arrays;

public class TestReflect1 {

    @Test
    public void GetClazz() throws ClassNotFoundException {
       Class<?> Student1=Class.forName("Student");
        Class<?> student2 = Student.class;
        Class<?> student3=new Student().getClass();
        System.out.println(Student1);//获得反射的字节码class对象
        System.out.println(student2.getName());//获取类的全路径
        System.out.println(student2.getSimpleName());//知获取类名
        System.out.println(student3.getPackage().getName());//获取名
    }

    @Test
    public void GetConstrust() throws ClassNotFoundException {
        Class<?> student1=Class.forName("Student");
        Class<?> student2 = Student.class;
        Class<?> student3=new Student().getClass();


       Constructor<?>[] constructor =student2.getConstructors();

        for (Constructor c:constructor) {
            System.out.println(c.getName());//获取构造方法的名字

            Class[] cp=c.getParameterTypes();
            System.out.println(Arrays.toString(cp));

        }

        Field[] field= student2.getDeclaredFields();
        for (Field f : field){

            System.out.println(f.getName());
            System.out.println(f.getType().getName());

        }



    }

  //h获取反射创建对象
    @Test
    public void getObject() throws Exception {
       //获取字节码对象
        Class<?> clazz=Class.forName("Student");
        //创建对象
        Object ob=clazz.newInstance();
        System.out.println(ob);

    }



}
